<?php
/**
 *
 * Created by PhpStorm.
 * User: jacky.yao
 * Date: 2020/4/21
 * Time: 11:41
 */

require_once 'bootstrap.php';

$reporterId = $argv[1];
$engineerId = $argv[2];
$productIds = explode(',', $argv[3]);

$reporter = $entityManager->find('User', $reporterId);
$engineer = $entityManager->find('User', $engineerId);

//if (!$reporter || !$engineer) {} {
if (!$reporter || !$engineer) {
    echo "No reporter and/or engineer found for the given id(s).\n";
    exit(1);
}

$bug = new Bug();
$bug->setDescription("Something does not work!");
$bug->setCreated(new DateTime('now'));
$bug->setStatus("OPEN");

foreach ($productIds as $productId) {
    $product = $entityManager->find('Product', $productId);
    $bug->assignToProduct($product);
}

$bug->setReporter($reporter);
$bug->setEngineer($engineer);
$entityManager->persist($bug);
$entityManager->flush();

echo "Your new bug Id: " . $bug->getId() . "\n";
